package test;
import std::IO;
import std::Type;

public class TestArrayStatement{
	
	public static test(){
		IO.printf("测试数组操作\n");
		
		{
			IO.printf("数组赋值\n");
			a->int[] = new int[3]{1,2,3};
			IO.printf("%d\n", Type.get(a[0]+=a[1]+=a[2]+=1));
			IO.printf("%d ", Type.get(a[0]));
			IO.printf("%d ", Type.get(a[1]));
			IO.printf("%d\n", Type.get(a[2]));
		}

		IO.printf("一维:\n");
		a->int[] = new int[5]{5,4,3};
		TestArrayStatement.show1d(a);

		IO.printf("二维:\n");
		b->int[][] = new int[2][2]{
			{1,3},
			{1,4}
		};
		TestArrayStatement.show2d(b);

		IO.printf("三维:\n");
		c->int[][][] = new int[2][2][2]{
			{
				{1,3},
				{1,4}
			},
			{
				{3,1},
				{4,1}
			}
		};
		TestArrayStatement.show3d(c);

		IO.printf("\n");
	}

	static show1d(a->int[]){
		IO.printf("[");
		i->int = 0;
		while(i<a.length){
			IO.printf("%d ", Type.get(a[i++]));
		}
		IO.printf("]");
		IO.printf("\n");
	}

	static show2d(a->int[][]){
		i->int = 0;
		while(i<a.length){
			IO.printf("[");
			j->int=0;
			while(j<a[i].length){
				IO.printf("%d ", Type.get(a[i][j++]));
			}
			IO.printf("]");
			++i;
		}
		IO.printf("\n");
	}

	static show3d(a->int[][][]){
		i->int = 0;
		while(i<a.length){
			j->int=0;
			while(j<a[i].length){
				IO.printf("[");
				k->int=0;
				while(k<a[i][j].length){
					IO.printf("%d ", Type.get(a[i][j][k++]));
				}
				++j;
				IO.printf("]");
			}
			++i;
			IO.printf("\n");
		}
	}
}